#大牛测试出品
#qq2574674466
import logging,time,os
from Common.function import  project_path
class FrameLog():
    def __init__(self, logger=None):


    # 创建一个logger
        self.logger = logging.getLogger(logger)
        self.logger.setLevel(logging.DEBUG)
    # 创建一个handler，用于写入日志文件
        self.log_time = time.strftime("%Y_%m_%d_")
       #路径需要修改
        self.log_path = os.path.join(project_path(), "Logs")
        if not os.path.exists(self.log_path):
             os.makedirs(self.log_path)

        self.log_name = os.path.join(self.log_path, self.log_time + 'log.log')
        print(self.log_name)
        fh = logging.FileHandler(self.log_name, 'a', encoding='utf-8')
        fh.setLevel(logging.INFO)

    # 定义handler的输出格式
        formatter = logging.Formatter('[%(asctime)s] %(filename)s->%(funcName)s line:%(lineno)d [%(levelname)s]%(message)s')
        fh.setFormatter(formatter)
        self.logger.addHandler(fh)

    #  添加下面一句，在记录日志之后移除句柄

     #   self.logger.removeHandler(fh)
    # 关闭打开的文件
        #fh.close()


    def log(self):
        return self.logger
if __name__ == '__main__':
    lo = FrameLog()
    log = lo.log()
    log.error("error")
    log.debug("debug")
    log.info("info")
    log.critical("严重")
